/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

var showinglist='null';
var selecteditem='null';
var selectedpic="pic2";
var scrollTimer;
var index = 0;

$(document).ready(function(){
    $("#item1").mouseover(function(){
        switchToItem('item1');
        switchToList('small');
    });
    $("#item2").mouseover(function(){
        switchToItem('item2');
        switchToList('small1');
    });
    $("#item3").mouseover(function(){
        switchToItem('item3');
        switchToList('small2');
    });
    $("#item4").mouseover(function(){
        switchToItem('item4');
        switchToList('small3');
    });
    $("#item5").mouseover(function(){
        switchToItem('item5');
        switchToList('small4');
    });
    $("#item6").mouseover(function(){
        switchToItem('item6');
        switchToList('small5');
    });
    $("#region1").mouseover(function(){
        switchToItem('region1');
        switchToList('small6');
    });
    $("#region2").mouseover(function(){
        switchToItem('region2');
        switchToList('small7');
    });
    $("#region3").mouseover(function(){
        switchToItem('region3');
        switchToList('small8');
    });
    $("#region4").mouseover(function(){
        switchToItem('region4');
        switchToList('small9');
    });
    $("#region5").mouseover(function(){
        switchToItem('region5');
        switchToList('small10');
    });
    $("#pic1").mouseover(function(){
        movebackground("pic1");
    });
    $("#pic2").mouseover(function(){
        movebackground("pic2");
    });
    $("#pic3").mouseover(function(){
        movebackground("pic3");
    });
    
    $("#login").click(function(){
		centerPopup();
		loadPopup();
	});
	
    $("#popupContactClose").click(function(){
		disablePopup();
	});
	
    $("#backgroundPopup").click(function(){
		disablePopup();
	});
	
    $(document).keypress(function(e){
		if(e.keyCode==27){
			disablePopup();
		}
	});

    startAnime();
})

function centerPopup(){
		var windowWidth = document.documentElement.clientWidth;
		var windowHeight = document.documentElement.clientHeight;
		var popupHeight = $("#popupContact").height(); 
		var popupWidth = $("#popupContact").width(); 
		
		$("#popupContact").css({   
			"position": "absolute",   
			"top": windowHeight/2-popupHeight/2,   
			"left": windowWidth/2-popupWidth/2 
		});
		
		//for ie6
		$("#backgroundPopup").css({   
			"height": windowHeight   
		}); 
	}
	
	//使用Jquery加载弹窗
function loadPopup(){
			$("#backgroundPopup").css({"opacity": "0.7"});
			$("#backgroundPopup").fadeIn("fast");
			$("#popupContact").fadeIn("fast");
	}
	
	//使用Jquery去除弹窗效果
function disablePopup(){
		$("#backgroundPopup").fadeOut("fast");
		$("#popupContact").fadeOut("fast");
	}

function ItemMap(){
    this.blocks=new Array();
    this.addPeer=function(item1,item2){
        this.blocks[item1]=item2;
    };
    this.get=function(key){
        return this.blocks[key];
    }
}

function jQueryHide(target){
    if($("#"+target).is(":animated")){
        $("#"+target).stop(true,true);
    }
    $("#"+target).hide(400);
    
}

function startAnime(){
		$('#description').hover(function(){
			clearInterval(scrollTimer);
		}, function(){
			window.clearInterval(scrollTimer);
			scrollTimer = setInterval(function(){
				++index;
				if (index > 2) { index = 0; }
                                switch(index){
                                    case 0:
                                        movebackground('pic2');
                                        break;
                                    case 1:
                                         movebackground('pic3');
                                         break;
                                    case 2:
                                        movebackground("pic1");
                                        break;
                                }
			}, 3000);
		}).trigger('mouseleave');
}

function hideCurrentList(){
    jQueryHide(showinglist);
    switchToItem('null');
    showinglist='null';
}

function jump(url){
    window.location.href=url;
}

function switchToList(target){
     if(showinglist!='null'){
            jQueryHide(showinglist);
        }
        jQueryShow(target)
        showinglist=target;
}

function switchToItem(target){
    if(selecteditem!=null){
        $("#"+selecteditem).css("font-size", "20px");
        $("#"+selecteditem).css("background-color", "#FFFFFF");
    }
    if(target!='null'){
    $("#"+target).css("font-size", "30px");
    $("#"+target).css("background-color", "buttonface");
    }
    selecteditem=target;
}

function movebackground(target){
    switch(target){
        case 'pic1':
            $("#description").css("background-position", "0px 0px");
            $("#pic1").css("background-color","#f59d56");
            $("#"+selectedpic).css("background-color", "#ffffff");
            selectedpic='pic1';
            break;
        case 'pic2':
            $("#description").css("background-position", "-700px 0px");
            $("#pic2").css("background-color","#f59d56");
            $("#"+selectedpic).css("background-color", "#ffffff");
            selectedpic='pic2';
            break;
        case 'pic3':
            $("#description").css("background-position", "-1400px 0px");
            $("#pic3").css("background-color","#f59d56");
            $("#"+selectedpic).css("background-color", "#ffffff");
            selectedpic='pic3';
            break;
    }
}

function jQueryShow(target){
    if($("#"+target).is(":animated")){
        $("#"+target).stop(true,true);
    }
    $("#"+target).show(400);
}

